<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <!-- 放置表单 -->
            <el-form
              ref="empForm"
              :model="empForm"
              :rules="rules"
              label-width="120px"
              style="margin-left: 120px; margin-top:30px"
            >
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="empForm.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="passTemp">
                <el-input v-model="empForm.passTemp" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="saveUserDetailById">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>

          <el-tab-pane label="个人详情">
            <!-- 放置个人详情 -->
            <component :is="componentName" />
            <!-- <user-info /> -->
          </el-tab-pane>

          <el-tab-pane label="岗位详情">
            <!-- 放置岗位详情 -->
            <JobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetailById, saveUserDetailById } from '@/api/employee'
import userInfo from './component/userInfo'
import JobInfo from './component/jobInfo'
export default {
  components: {
    userInfo,
    JobInfo
  },
  data() {
    return {
      componentName: 'userInfo',
      empId: this.$route.params.id,
      empForm: {
        username: '',
        password: '',
        passTemp: ''
      },
      rules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        passTemp: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserDetailById()
  },
  methods: {
    async getUserDetailById() {
      this.empForm = await getUserDetailById(this.empId)
      console.log(this.empForm)
    },
    async saveUserDetailById() {
      await this.$refs.empForm.validate()
      await saveUserDetailById({ ...this.empForm, password: this.empForm.passTemp })
      this.$message.success('更新员工信息成功')
    }
  }
}
</script>

<style>

</style>
